//
//  cinemaViewController.m
//  C17
//
//  Created by dllo on 16/3/17.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "cinemaViewController.h"
#import "CityCinemaTableViewCell.h"
#import "CitySearchTableViewCell.h"
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
#import "YingYuanViewController.h"

@interface cinemaViewController ()<UITableViewDataSource,UITableViewDelegate,CLLocationManagerDelegate,UISearchResultsUpdating>
{
    //CLLocationManager 切记定义成成员变量、或者属性，否则导致不弹出系统提示打开定位提示框
    CLLocationManager *_locationManager;
    MKMapView *_mapView;
    CLGeocoder *_geocoder;
    CLLocationCoordinate2D coordinate;
    UIWebView *webView;
}
@property(nonatomic,retain)NSMutableArray *searchList;
@property(nonatomic,strong)UISearchController *searchController;
@property(nonatomic,strong)NSMutableArray *searchArr;
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property(nonatomic,strong)NSArray *arr;
@property(nonatomic,strong)NSMutableArray *DistanceArr;
@property(nonatomic,strong)NSString *City;

@property(nonatomic,strong)NSMutableArray *pingfenArr;
@property(nonatomic,strong)NSMutableArray *zuoArr;
@property(nonatomic,assign)NSInteger geshu;
@property(nonatomic,assign)NSInteger geshu2;
@end

@implementation cinemaViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    //searchcontroller
    
    //定位   解析数据
    [self getPlace];
    
    self.title=@"影院";
    
    self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
    _searchController.searchBar.frame = CGRectMake(self.searchController.searchBar.frame.origin.x, self.searchController.searchBar.frame.origin.y, self.searchController.searchBar.frame.size.width, 44);//尺寸
    
    //_searchController.dimsBackgroundDuringPresentation = NO;//遮挡板
    _searchController.hidesNavigationBarDuringPresentation = NO;//导航控制器视图(不改会变没)
    _searchController.obscuresBackgroundDuringPresentation = NO;//不光能看
    
    _searchController.searchResultsUpdater = self;
    [self.view addSubview:_searchController.searchBar];
    
    [_tableView registerNib:[UINib nibWithNibName:NSStringFromClass([CityCinemaTableViewCell class]) bundle:nil] forCellReuseIdentifier:@"tableView"];
    [_tableView registerNib:[UINib nibWithNibName:NSStringFromClass([CitySearchTableViewCell class]) bundle:nil] forCellReuseIdentifier:@"tableView2"];
    _tableView.rowHeight=150;
    _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    
    self.dingweiLabel.text=@"正在定位,请稍后...";
    self.downView.layer.cornerRadius=5;
    [self.shuaxin addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
    CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    //设置动画起始的值
    animation.fromValue=[NSNumber numberWithFloat:0];
    //设置最终旋转的角度
    animation.toValue=[NSNumber numberWithFloat:M_PI*2];
    //设置动画的播放时长
    animation.duration=1;
    //设置动画的执行次数(NSIntegerMax整数的最大值)
    animation.repeatCount=NSIntegerMax;
    [self.shuaxin.layer addAnimation:animation forKey:@"transform.rotation"];
    
    
    
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"link-2" ofType:@"gif"];
    NSData *gifData = [NSData dataWithContentsOfFile:path];
    webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    webView.center=CGPointMake(WIDTH/2, HEIGHT/2);
    webView.backgroundColor = [UIColor redColor];
    webView.scalesPageToFit = YES;
    [webView loadData:gifData MIMEType:@"image/gif" textEncodingName:nil baseURL:nil];
    [self.tableView addSubview:webView];
     //这样就不会出现白的底色，当然，前提是gif的每个桢图也是背景透明的。
     //[webView setOpaque:NO]
    
    
}
-(void)click{
    //动画开启
    self.shuaxin.layer.speed=1;
    webView.hidden=NO;
    [self getPlace];
}



-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (self.searchController.active) {
        return self.searchList.count;
    }
    else{
        return self.arr.count;
    }
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.searchController.active) {
        CitySearchTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"tableView2" forIndexPath:indexPath];
        self.tableView.rowHeight=50;
        for (NSString *temp in self.searchArr) {
            if (temp==self.searchList[indexPath.row]) {
                NSString *string1 = temp;
                NSRange range1=[_City rangeOfString:@"市"];
                if (range1.length!=0) {
                    NSString *string2 = [_City substringToIndex:range1.location];
                    NSRange range = [string1 rangeOfString:string2];
                    if (range.length!=0) {
                        NSString *str = [string1 stringByReplacingCharactersInRange:range withString:@""];
                        cell.searchLabel.text=str;
                    }
                    else{
                        cell.searchLabel.text=string1;
                    }
                }
                else{
                    NSString *string2 = _City;
                    NSRange range = [string1 rangeOfString:string2];
                    if (range.length!=0) {
                        NSString *str = [string1 stringByReplacingCharactersInRange:range withString:@""];
                        cell.searchLabel.text=str;
                    }
                    else{
                        cell.searchLabel.text=string1;
                    }
                }
            }
        }
        return cell;
    }
    else{
        CityCinemaTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"tableView" forIndexPath:indexPath];
        _tableView.rowHeight=150;
        NSDictionary *dic=self.arr[indexPath.row];
        NSString *Distance=self.DistanceArr[indexPath.row];
        //NSString *strFen=self.pingfenArr[indexPath.row];
        NSDictionary *tuDic=self.zuoArr[indexPath.row];
    
    //评分
        AFHTTPSessionManager *manager1=[AFHTTPSessionManager manager];
        [manager1.responseSerializer setAcceptableContentTypes:[NSSet setWithObjects:@"text/html", @"application/json", @"text/json", @"text/javascript",@"text/html",@"text/css", @"text/plain", @"application/x-javascript", @"application/javascript",nil]];
        NSString *str1=[NSString stringWithFormat:@"http://api.m.mtime.cn/Showtime/ShowTimesByCinemaMovieDate.api?cinemaId=%@&date=2016-03-19",dic[@"id"]];
        [manager1 GET:str1 parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            CGFloat fen=[responseObject[@"rating"] floatValue];
            DisplayStarView *display=[[DisplayStarView alloc] initWithFrame:CGRectMake(0, 0, 66, 21)];
            [cell.pingfen addSubview:display];
            display.showStar=fen*10;
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            NSLog(@"error=%@",error);
        }];
    
    //遍历解析影院详细信息
//        AFHTTPSessionManager *manager=[AFHTTPSessionManager manager];
//        [manager.responseSerializer setAcceptableContentTypes:[NSSet setWithObjects:@"text/html", @"application/json", @"text/json", @"text/javascript",@"text/html",@"text/css", @"text/plain", @"application/x-javascript", @"application/javascript",nil]];
//        NSString *str=[NSString stringWithFormat:@"http://api.m.mtime.cn/Showtime/ShowtimeMovieAndDateListByCinema.api?cinemaId=%@",dic[@"id"]];
//        [manager GET:str parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//            NSDictionary *tuDic=responseObject[@"cinema"][@"feature"];
            cell.label1.text=@"座";
            cell.label1.textColor=[UIColor colorWithRed:131/256.0 green:175/256.0 blue:155/256.0 alpha:1];
            cell.label1.layer.borderWidth=1;
            cell.label1.layer.borderColor=[[UIColor colorWithRed:131/256.0 green:175/256.0 blue:155/256.0 alpha:1] CGColor];
            NSInteger  hasIMAX=[tuDic[@"hasIMAX"] integerValue];
            if (hasIMAX==1) {
                cell.label2.text=@"IMAX";
                cell.label2.textColor=[UIColor colorWithRed:131/256.0 green:175/256.0 blue:155/256.0 alpha:1];
                cell.label2.layer.borderWidth=1;
                cell.label2.layer.borderColor=[[UIColor colorWithRed:131/256.0 green:175/256.0 blue:155/256.0 alpha:1] CGColor];
                cell.label2.frame=CGRectMake(cell.label2.frame.origin.x, cell.label2.frame.origin.y, 50, 20);
                NSInteger  hasFood=[tuDic[@"hasFood"] integerValue];
                if (hasFood==1) {
                    cell.label3.text=@"小吃";
                    cell.label3.textColor=[UIColor whiteColor];
                    cell.label3.backgroundColor=[UIColor colorWithRed:217/255.0 green:104/255.0 blue:49/255.0 alpha:1];
                    NSInteger  hasPark=[tuDic[@"hasPark"] integerValue];
                    if (hasPark==1) {
                        cell.label4.text=@"停车";
                        cell.label4.textColor=[UIColor whiteColor];
                        cell.label4.backgroundColor=[UIColor colorWithRed:6/255.0 green:128/255.0 blue:67/255.0 alpha:1];
                    }
                }
            }
            else{
                NSInteger  hasVIP=[tuDic[@"hasVIP"] integerValue];
                if (hasVIP==1) {
                    cell.label2.text=@"VIP";
                    cell.label2.textColor=[UIColor colorWithRed:131/256.0 green:175/256.0 blue:155/256.0 alpha:1];
                    cell.label2.layer.borderWidth=1;
                    cell.label2.layer.borderColor=[[UIColor colorWithRed:131/256.0 green:175/256.0 blue:155/256.0 alpha:1] CGColor];
                }
                else{
                    NSInteger  has4D=[tuDic[@"has4D"] integerValue];
                    if (has4D==1) {
                        cell.label2.text=@"4D";
                        cell.label2.textColor=[UIColor whiteColor];
                        cell.label2.backgroundColor=[UIColor colorWithRed:217/255.0 green:104/255.0 blue:49/255.0 alpha:1];
                        cell.label2.frame=CGRectMake(cell.label2.frame.origin.x, cell.label2.frame.origin.y, 50, 20);
                    }
                }
            }
//        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//            NSLog(@"error=%@",error);
//        }];

    
    
    
    
    
    //判断名字,删除本地字样
    NSString *string1 = dic[@"name"];
    NSRange range1=[_City rangeOfString:@"市"];
    if (range1.length!=0) {
        NSString *string2 = [_City substringToIndex:range1.location];
        NSRange range = [string1 rangeOfString:string2];
        if (range.length!=0) {
            NSString *str = [string1 stringByReplacingCharactersInRange:range withString:@""];
            cell.CinemaName.text=str;
        }
        else{
            cell.CinemaName.text=string1;
        }
    }
    else{
        NSString *string2 = _City;
        NSRange range = [string1 rangeOfString:string2];
        if (range.length!=0) {
            NSString *str = [string1 stringByReplacingCharactersInRange:range withString:@""];
            cell.CinemaName.text=str;
        }
        else{
            cell.CinemaName.text=string1;
        }
    }
    
    //简述的判断
    NSRange descRange=[dic[@"address"] rangeOfString:_City];
    if (descRange.length==0) {
        if (range1.length!=0) {
            descRange = range1;
            cell.Cinemadesc.text=[dic[@"address"] stringByReplacingCharactersInRange:descRange withString:@""];
        }
    }
    if (descRange.length!=0) {
        cell.Cinemadesc.text=[dic[@"address"] stringByReplacingCharactersInRange:descRange withString:@""];
    }
    else{
        cell.Cinemadesc.text=dic[@"address"];
    }
    
    //cell.pingfen.text=fenStr;
    
    CGFloat juli=[Distance integerValue]/1000.0;
    if (juli>0.99) {
        cell.juli.text=[NSString stringWithFormat:@"%.1fkm",juli];
//        //富文本对象
//        NSMutableAttributedString * aAttributedString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%.1fkm",juli]];
//        //富文本样式
//        [aAttributedString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 4)];
//        [aAttributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:25] range:NSMakeRange(0, 4)];
    }
    else{
        cell.juli.text=[NSString stringWithFormat:@"%@m",Distance];
    }
    return cell;
    }
}

#pragma mark ----先定位
-(void)getPlace{
    //请求定位服务(在info中配置NSLocationWhenInUseUsageDescription)
    _locationManager=[[CLLocationManager alloc]init];
    if(![CLLocationManager locationServicesEnabled]||[CLLocationManager authorizationStatus]!=kCLAuthorizationStatusAuthorizedWhenInUse){
        [_locationManager requestWhenInUseAuthorization];
    }
    else if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusAuthorizedWhenInUse){
        //设置代理
        _locationManager.delegate=self;
        //设置定位精度
        _locationManager.desiredAccuracy=kCLLocationAccuracyBest;
        //定位频率,每隔多少米定位一次
        CLLocationDistance distance=10.0;//十米定位一次
        _locationManager.distanceFilter=distance;
        //启动跟踪定位
        [_locationManager startUpdatingLocation];
        
        //用户位置追踪(用户位置追踪用于标记用户当前位置，此时会调用定位服务)
        _mapView.userTrackingMode=MKUserTrackingModeFollow;
        
    }
}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
    CLLocation *location=[locations firstObject];//取出第一个位置
    coordinate=location.coordinate;//位置坐标
    NSLog(@"经度：%f,纬度：%f,海拔：%f,航向：%f,行走速度：%f",coordinate.longitude,coordinate.latitude,location.altitude,location.course,location.speed);
    //如果不需要实时定位，使用完即使关闭定位服务
    [_locationManager stopUpdatingLocation];
    
    _geocoder=[[CLGeocoder alloc]init];
    [self getAddressByLatitude:coordinate.latitude longitude:coordinate.longitude];
}
#pragma mark 根据坐标取得地名
-(void)getAddressByLatitude:(CLLocationDegrees)latitude longitude:(CLLocationDegrees)longitude{
    //反地理编码
    CLLocation *location=[[CLLocation alloc]initWithLatitude:latitude longitude:longitude];
    [_geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
        CLPlacemark *placemark=[placemarks firstObject];
        //NSLog(@"详细信息:%@",placemark.addressDictionary);
        self.dingweiLabel.text=[NSString stringWithFormat:@"%@%@",placemark.addressDictionary[@"SubLocality"],placemark.addressDictionary[@"Name"]];
        //让动画停止
        self.shuaxin.layer.speed=0;
        [self getDataCity:placemark.addressDictionary[@"City"]];
        self.City=placemark.addressDictionary[@"City"];
    }];
}
-(void)getDataCity:(NSString *)city{
    NSString *str=[NSString stringWithFormat:@"http://api.m.mtime.cn/GetCityByLongitudelatitude.api?longitude=%f&latitude=%f&cityName=%@",coordinate.longitude,coordinate.latitude,city];
    str=[str stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet characterSetWithCharactersInString:str]];
//    NSLog(@"%@",str);
    //第一层确定城市名称
    AFHTTPSessionManager *manager=[AFHTTPSessionManager manager];
    [manager.responseSerializer setAcceptableContentTypes:[NSSet setWithObjects:@"text/html", @"application/json", @"text/json", @"text/javascript",@"text/html",@"text/css", @"text/plain", @"application/x-javascript", @"application/javascript",nil]];
    [manager GET:str parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        //第二层对应城市所有影院
        AFHTTPSessionManager *manager=[AFHTTPSessionManager manager];
        [manager.responseSerializer setAcceptableContentTypes:[NSSet setWithObjects:@"text/html", @"application/json", @"text/json", @"text/javascript",@"text/html",@"text/css", @"text/plain", @"application/x-javascript", @"application/javascript",nil]];
        [manager GET:[NSString stringWithFormat:@"http://api.m.mtime.cn/Showtime/BaseCityData.api?locationid=%@",responseObject[@"cityId"]] parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            //解析对应城市所有影院信息
            NSMutableArray *arr= [NSMutableArray arrayWithArray:responseObject[@"cinemas"]];
            [self compare:(NSMutableArray *)arr];
            self.arr=arr;
            webView.hidden=YES;
            _tableView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
            
            self.pingfenArr=[NSMutableArray array];
            for (int i; i<self.arr.count; i++) {
                [self.pingfenArr addObject:@"1"];
            }

            self.zuoArr=[NSMutableArray array];
            for (int i; i<self.arr.count; i++) {
                [self.pingfenArr addObject:responseObject[@"cinemas"]];
            }
            self.geshu=0;
            self.geshu2=0;
            for (NSDictionary *dic in self.arr) {
                //评分
//                AFHTTPSessionManager *manager1=[AFHTTPSessionManager manager];
//                [manager1.responseSerializer setAcceptableContentTypes:[NSSet setWithObjects:@"text/html", @"application/json", @"text/json", @"text/javascript",@"text/html",@"text/css", @"text/plain", @"application/x-javascript", @"application/javascript",nil]];
//                NSString *str1=[NSString stringWithFormat:@"http://api.m.mtime.cn/Showtime/ShowTimesByCinemaMovieDate.api?cinemaId=%@&date=2016-03-19",dic[@"id"]];
//                NSLog(@"%@",str1);
//                [manager1 GET:str1 parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//                    NSString *strFen=[NSString stringWithFormat:@"%@分",responseObject[@"rating"]];
//                    NSLog(@"%@",strFen);
//                    self.pingfenArr[self.geshu]=strFen;
//                    self.geshu++;
//                    if (self.geshu==self.arr.count) {
//                        [self.tableView reloadData];
//                    }
//                } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//                    NSLog(@"error=%@",error);
//                }];
                
                
                AFHTTPSessionManager *manager=[AFHTTPSessionManager manager];
                [manager.responseSerializer setAcceptableContentTypes:[NSSet setWithObjects:@"text/html", @"application/json", @"text/json", @"text/javascript",@"text/html",@"text/css", @"text/plain", @"application/x-javascript", @"application/javascript",nil]];
                NSString *str=[NSString stringWithFormat:@"http://api.m.mtime.cn/Showtime/ShowtimeMovieAndDateListByCinema.api?cinemaId=%@",dic[@"id"]];
                [manager GET:str parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                    NSDictionary *tuDic=responseObject[@"cinema"][@"feature"];
                    [self.zuoArr addObject:tuDic];
                    self.geshu2++;
                    if (self.geshu2==self.arr.count) {
                        [self.tableView reloadData];
                    }
                } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                    NSLog(@"error=%@",error);
                }];
            }
            
            
            
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            NSLog(@"error=%@",error);
        }];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"error=%@",error);
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
//数组按距离排序
-(void)compare:(NSMutableArray *)arr{
    for (NSInteger i=0; i<arr.count-1; i++) {
        for (NSInteger j=0; j<arr.count-i-1; j++) {
            //定位点坐标
            CLLocation *locationBase=[[CLLocation alloc]initWithLatitude:coordinate.latitude longitude:coordinate.longitude];
            
            //计算字典和下一个字典哪个距离定位点距离
            double latitude1= [arr[j][@"latitude"] doubleValue];
            if (latitude1==0) {
                latitude1=[arr[j][@"baiduLatitude"] doubleValue];
            }
            double longitude1= [arr[j][@"longitude"] doubleValue];
            if (longitude1==0) {
                longitude1=[arr[j][@"baiduLongitude"] doubleValue];
            }
            CLLocation *location1=[[CLLocation alloc]initWithLatitude:latitude1 longitude:longitude1];
            CLLocationDistance locationDistance1=[locationBase distanceFromLocation:location1];
            
            double latitude2= [arr[j+1][@"latitude"] doubleValue];
            if (latitude2==0) {
                latitude2=[arr[j+1][@"baiduLatitude"] doubleValue];
            }
            double longitude2= [arr[j+1][@"longitude"] doubleValue];
            if (longitude2==0) {
                longitude2=[arr[j+1][@"baiduLongitude"] doubleValue];
            }
            CLLocation *location2=[[CLLocation alloc]initWithLatitude:latitude2 longitude:longitude2];
            CLLocationDistance locationDistance2=[locationBase distanceFromLocation:location2];
            if (locationDistance1>locationDistance2) {
                NSDictionary *temp=arr[j];
                arr[j]=arr[j+1];
                arr[j+1]=temp;
            }
        }
    }
    //添加距离的数组
    self.DistanceArr=[NSMutableArray array];
    self.searchArr=[NSMutableArray array];
    for (NSInteger i=0; i<arr.count; i++) {
        CLLocation *locationBase=[[CLLocation alloc]initWithLatitude:coordinate.latitude longitude:coordinate.longitude];
        
        double latitude= [arr[i][@"latitude"] doubleValue];
        if (latitude==0) {
            latitude=[arr[i][@"baiduLatitude"] doubleValue];
        }
        double longitude= [arr[i][@"longitude"] doubleValue];
        if (longitude==0) {
            longitude=[arr[i][@"baiduLongitude"] doubleValue];
        }
        CLLocation *location=[[CLLocation alloc]initWithLatitude:latitude longitude:longitude];
        CLLocationDistance locationDistance=[locationBase distanceFromLocation:location];
        NSString *DistanceStr=[NSString stringWithFormat:@"%.f",locationDistance];
        [_DistanceArr addObject:DistanceStr];
        
        [self.searchArr addObject:arr[i][@"name"]];

    }

}

-(void)updateSearchResultsForSearchController:(UISearchController *)searchController {
    NSString *searchString = [self.searchController.searchBar text];
    NSPredicate *preicate = [NSPredicate predicateWithFormat:@"SELF CONTAINS[c] %@", searchString];//谓词,如果当前search controller的内容与下面内容相匹配,实现搜索功能
    if (self.searchList!= nil) {
        [self.searchList removeAllObjects];
    }
    //过滤数据
    self.searchList= [NSMutableArray arrayWithArray:[self.searchArr filteredArrayUsingPredicate:preicate]];//根据设置的东西,把数据一层层筛选
//    for (int i = 0; i < self.searchArr.count; i++) {
//        NSLog(@"---------%d , %@"  , self.searchArr.count , self.searchArr[i]);
//
//    }
//    for (int i = 0; i < self.searchList.count; i++) {
//
//    NSLog(@"========%d , %@"  , self.searchList.count , self.searchList[i]);
//    }
    //刷新表格
    [self.tableView reloadData];
}

#pragma mark 滑动就触发的方法
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    self.downView.hidden=YES;
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    self.downView.hidden=NO;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    YingYuanViewController *vc=[[YingYuanViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

@end
